package createoffer.data;

import java.util.ArrayList;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LocationTests {

	private int startSize;

	public void runTests(ArrayList<String> codeInjection, int codeInjectionSize) {
		ArrayList<String> webElements = new ArrayList<String>();
		webElements.add("offer_location");
		webElements.add("email");
		webElements.add("password");
		codeInjections(codeInjection, codeInjectionSize, webElements);
	}

	private void codeInjections(ArrayList<String> codeInjection,
			int codeInjectionSize, ArrayList<String> webElements) {
		for(startSize = 0; startSize < codeInjectionSize; startSize++){
			WebDriver driver = new FirefoxDriver();
			driver.get("https://snapsation.com/login");
			WebElement email = driver.findElement(By.name(webElements.get(1)));
			email.sendKeys("damciodamcio666@gmail.com");
			WebElement password = driver.findElement(By.name(webElements.get(2)));
			password.sendKeys("admin123admin");
			email.submit();
			//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
			/*WebElement offers = driver.findElement(By.linkText("/offer/"));
			offers.click();*/
			try {
				Thread.sleep(1800);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			driver.get("https://snapsation.com/offer/new/");
			WebElement title = driver.findElement(By.name(webElements.get(0)));
			title.sendKeys(codeInjection.get(startSize));
			title.submit();
			try {
				Thread.sleep(1800);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}
